> score
student_number semester math_score english_score
1 1 1 60 80
2 2 1 90 70
3 1 2 80 40
4 2 2 90 60
> library(reshape)
> melt(score, id=c("student_number", "semester"))
student_number semester variable value
1 1 1 math_score 60
2 2 1 math_score 90
3 1 2 math_score 80
4 2 2 math_score 90
5 1 1 english_score 80
6 2 1 english_score 70
7 1 2 english_score 40
8 2 2 english_score 60
> melted_score<-melt(score, id=c("student_number", "semester”))
# 학생들의 과목별 평균 과목
> cast(melted_score, student_number~variable, mean)
student_number math_score english_score
1 1 70 60
2 2 90 65
#학생의 학기별 평균 점수
> cast(melted_score, student_number~semester, mean)
student_number 1 2
1 1 70 60
2 2 80 75
#학생의 과목별 최댓값
> cast(melted_score, student_number~variable, max)
student_number math_score english_score
1 1 80 80
2 2 90 70